#include "ShiftRegister.h"





void initShiftReg( void ){
  /*init Ports*/
  DDRA |= (1<<DDA7);
  DDRC |= (1<<DDC7);
  DDRD |= (1<<DDA6);
  
  PORTSCK |= SCK;
  PORTRCK |= RCK;
};

void SetVolumeAndInput(int Volume, int Input){
  SendBitShiftReg(Input,0);
  SendBitShiftReg(Volume,1);
};

void SendBitShiftReg(int value, int EnableOutput){
  int i,j;
  int Delay = 150;
  int SendBuffer;
  for(i=7;i>=0;i--){
    SendBuffer = (0x01) & (value >> i);
    if(SendBuffer == 1){
      PORTSER |= SER;
      
    }else{
      PORTSER &= ~SER;
      
    };
    PORTSCK &= ~SCK;
    for(j=0;j< Delay;j++);
    PORTSCK |= SCK;
    for(j=0;j< Delay;j++);
  };
  if(EnableOutput){
    for(j=0;j< Delay;j++);
    PORTRCK &= ~RCK;
    for(j=0;j< Delay;j++);
    PORTRCK |= RCK;
    for(j=0;j< Delay;j++);
  }

  
};
